package com.xzgj.fmmall.controller;

import com.xzgj.fmmall.entity.Interests;
import com.xzgj.fmmall.entity.User;
import com.xzgj.fmmall.service.InterestsService;
import com.xzgj.fmmall.vo.ResStatus;
import com.xzgj.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/interest")
@Api(value = "提供用户的兴趣爱好管理接口",tags = "兴趣爱好管理")
public class InterestsController {

    @Resource
    private InterestsService interestsService;

    @ApiOperation("根据interestsId查询兴趣爱好")
    @GetMapping(value = "/listByInterestsId")
    public ResultVO listInterests(Integer interestsId, @RequestHeader("token") String token){
        ResultVO resultVO = interestsService.queryInterestsByInterestsId(interestsId);
        return resultVO;
    }

    @ApiOperation("用户兴趣爱好列表")
    @GetMapping(value = "/list")
    public ResultVO queryInterests(@RequestHeader("token") String token){
        ResultVO resultVO = interestsService.queryInterests();
        return resultVO;
    }

    @ApiOperation("添加用户兴趣爱好")
    @PostMapping(value = "/add")
    public ResultVO insertAddr(String userId, @RequestBody Interests interests, @RequestHeader("token") String token){
        ResultVO resultVO = interestsService.insertInterests(interests);
        return resultVO;
    }

    @ApiOperation("更新/修改用户兴趣爱好")
    @PutMapping(value = "/info")
    public ResultVO updateInterestsInfoByInterestsId(@RequestBody Interests interests, @RequestHeader("token") String token){
        return interestsService.updateInterestsInfoByInterestsId(interests);
    }

    @ApiOperation("根据interestsId删除用户兴趣爱好")
    @DeleteMapping(value = "/delByInterestsId")
    public ResultVO deleteInterests(int interestsId, @RequestHeader("token") String token){
        ResultVO resultVO = null;
        try {
            resultVO = interestsService.deleteInterestsInfoByInterestsId(interestsId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return resultVO;
    }
}
